package com.luyue.zagj.utils;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;

import com.luyue.zagj.R;
import com.tianditu.android.maps.GeoPoint;
import com.tianditu.android.maps.MapView;
import com.tianditu.android.maps.Overlay;
import com.tianditu.android.maps.OverlayItem;

/**
 * Created by Chen qin lang on 2016/12/14.
 * 邮箱 :   619766577@qq.com
 */
public class MyOverlayUtil extends Overlay {
        private Context mCon = null;
        private OverlayItem mItem = null;
        private Paint       mPaint= null;
        public MyOverlayUtil(Context con)
        {
            mCon = con;
            mPaint = new Paint();
        }
        @Override
        public boolean onTap(GeoPoint point, MapView mapView) {
            // TODO Auto-generated method stub
            // 标记点击的坐标位置
            mItem = new OverlayItem(point, "Tap", point.toString());
            mapView.postInvalidate();
            return true;
        }
        @Override
        public void draw(Canvas canvas, MapView mapView, boolean shadow){
            // TODO Auto-generated method stub
            super.draw(canvas, mapView, shadow);
            if(mItem == null)
                return;
		/*
        * 以下为绘制点击位置及其坐标
         */
            Drawable d = mCon.getResources().getDrawable(R.mipmap.a);
            Point point = mapView.getProjection().toPixels(mItem.getPoint(), null);
            d.setBounds(point.x - d.getIntrinsicWidth()/2, point.y-d.getIntrinsicHeight(),
                    point.x + d.getIntrinsicWidth()/2, point.y);
            d.draw(canvas);
            Rect bounds = new Rect();
            mPaint.getTextBounds(mItem.getSnippet(), 0, mItem.getSnippet().length()-1, bounds);
            //显示坐标文本
            canvas.drawText(mItem.getSnippet(), point.x-bounds.width()/2,
                    point.y-d.getIntrinsicHeight(), mPaint);
        }


}
